<%@page import="com.googlecode.contests_repo.core.config.ConfigurationManager"%>
<%@page import="com.googlecode.contests_repo.core.users.AccessRight"%>
<%@page import="com.googlecode.contests_repo.core.users.UserManager"%>
<%@page import="com.googlecode.contests_repo.core.model.Problem"%>
<%@page import="com.googlecode.contests_repo.core.model.Contest"%>
<%@page import="com.googlecode.contests_repo.core.model.Resource"%>
<%@page import="com.googlecode.contests_repo.core.model.ResourcesUtils"%>
<%@page import="java.io.File"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Contest</title>
</head>
<body>
<%@include file='header.jsp'%>
<%
     String seriesTitle = request.getParameter("series");
     String contestTitle = request.getParameter("contest");
     String contestPath = ConfigurationManager.getInstance().getRepoRoot() 
     			+ File.separator + seriesTitle + File.separator + contestTitle;
     String publicFolder = "_public_files";
     String privateFolder = "_files";
     Contest contest = ResourcesUtils.getJSON(new File(contestPath));
     String loggedUser = (String)session.getAttribute("username");
%>
 	   
	<h1>Contest Info</h1>
	<p>
		<font size="4"> <b>Title: </b> <%=contest.getTitle()%> </font>
	</p>
	<p>
		<font size="4"> <b>About: </b> <%=contest.getAbout()%> </font>
	</p>
	<p>
		<font size="4"> <b>Start time: </b> <%=contest.getStartTime()%> </font>
	</p>
	<p>
		<font size="4"> <b>Duration: </b> <%=contest.getDuration()%> </font>
	</p>
	<p>
		<font size="4"> <b>Grading style</b> <%=contest.getGradingStyle()%> </font>
	</p>
	<% 
		if (ResourcesUtils.hasStarted(contest.getStartTime())){ %>
	<p>
		<font size="4"> <b>Problem order: </b>
		<%	for(String problemName: contest.getProblemOrder()){ %>
			<%=problemName%>
		<%	} %>
		</font></p>
	<p>
		<font size="4"> <b>Problem scores: </b>
		<%	for(Integer problemScore: contest.getProblemScores()){ %>
			<%=problemScore%>
		<%	} %>
		</font></p>
	<%	
		}
	    if (UserManager.hasAccessRight(loggedUser, contestPath, AccessRight.VIEW_FULL))
				{
	%>
	<p>
		<font size="4"> <b>Notes: </b> <%=contest.getNotes()%> </font>
	</p>
	<%
	    }
	%>
	<br />
	<h2>Problems:</h2>
	<table border=1>
		<tr>
			<th>Title</th>
			<th>About</th>
			<th>View</th>
		</tr>
		<%
		    List<Problem> problemList = ResourcesUtils.fetchResources(new File(
						    contestPath));
				    if (problemList != null)
				    {
						for (Problem problem : problemList)
						{
						    String problemPath = contestPath + File.separator + problem.getTitle();
						    if(UserManager.hasAccessRight(loggedUser, problemPath, AccessRight.LIST))
						    {
		%>
		<tr>
			<td><%=problem.getTitle()%></td>
			<td><%=problem.getAbout()%></td>
			<td><a
				href="problem.jsp?series=<%=seriesTitle%>&contest=<%=contestTitle%>&problem=<%=problem.getTitle()%>">details</a>
			</td>
		</tr>
		<%
		    		}
		    	}
		    }
		%>
	</table>
	<br />
		<h2>Downloads:</h2>
			<table border=1>
				<tr>
					<th>Folder name</th>
					<th>Download</th>
				</tr>
				<% 
					if (new File(contestPath + File.separator + publicFolder).exists()
							&&ResourcesUtils.hasStarted(contest.getStartTime())){%>
				<tr>
					<td><%=publicFolder%></td>
					<td><a
						href="download_folder.jsp?from=contest&series=<%=seriesTitle%>&contest=<%=contestTitle%>&folder=<%=publicFolder%>">download</a>
					</td>
				</tr>
				<%
					}
				    if (new File(contestPath + File.separator + privateFolder).exists()
					    	&&UserManager.hasAccessRight(loggedUser, contestPath,
								    AccessRight.VIEW_FULL))
						    {
				%>
				<tr>
					<td><%=privateFolder%></td>
					<td><a
						href="download_folder.jsp?from=contest&series=<%=seriesTitle%>&contest=<%=contestTitle%>&folder=<%=privateFolder%>">download</a>
					</td>
				</tr>
				<%
						    }
				%>
				</table>
	<br />
<a href="series.jsp?series=<%=seriesTitle%>">Back</a>
</body>
</html>